## postgresql – Why is there “no unique constraint” error for primary keys?

I have following table:

create table tbl (id_p int, id_c int, primary key (id_p, id_c));


I want to create a new table:

create table tbl_tbl (id_p int references tbl(id_p), id_c int references tbl(id_c), primary key (id_p, id_c));


But this command fails with the following error:

ERROR:  there is no unique constraint matching given keys for referenced table "tbl"


But the following command works:

create table tbl_tbl (id_p int, id_c int, primary key (id_p, id_c), foreign key (id_p, id_c) references tbl (id_p, id_c));


Why does this work where are the earlier command to create a table failed? How are these two ways of creating a table different?

## blockchain – All Bitcoin Public Keys with non-zero balance

You can’t get a database of all such public keys, but you can get some of them.

An address, as you know, is a hash of a public key. When somebody sends coins to an address, you can think of the associated public key as having a positive balance, but nobody else necessarily knows what the public key actually is. (You can’t compute the public key directly from the address, because hash functions are effectively one way.)

However, in order to spend the coins from that address, the spending transaction has to reveal the public key (so that the spending transaction’s signature can be verified). So what you need to look for are addresses with a positive balance that have also had some coins spent. I am not aware of any simple way to do this short of making an index of all transactions. It is possible you could rig up a way to produce such a list by querying a fully-synced bitcoind using -txindex (so that all transactions are indexed), but it seems likely to be inefficient.

But as a randomly chosen example, consider the address 1Q6NNpHM1pyh6kEqzinBhEgsRc3nmpTGLm. It is associated with some public key which has a balance of BTC 259.7299, but since (as of this writing) no coins have been spent from that address, nobody except the owner of the address knows what the public key is. So your database will necessarily be incomplete; probably very incomplete.

In particular, most people use a new address for each of their transactions (including change addresses), in which case the transaction that reveals the public key for an address also spends all its coins (so that the balance is now zero), and that public key will likely never be used again. This strategy is used partly because certain theoretical cryptographic attacks are easier if the public key is known, and this strategy mitigates the risk from such attacks; it also increases privacy by making it harder to look at patterns of transactions to try to deduce who the address belongs to.

Another case in which you can learn the public key is so-called P2PK transactions, where the output script includes the actual destination public key, instead of merely its associated address. These were common in the past, but these days all standard clients use the P2PKH transaction type, in which only the address is used.

## unity – How can I make this controllable with the W A S D keys and not the mouse?

Thanks for contributing an answer to Game Development Stack Exchange!

But avoid

• Making statements based on opinion; back them up with references or personal experience.

Use MathJax to format equations. MathJax reference.

## windows 10 – Autohotkey, combing two keys into one key?

I am trying to combine two keys into one key.
For example, a single hold of A, holds down A but a double tap and hold of A holds 1 key.

Below is what I so far have, it just repeats A key, it does not wait for me to release it. Any help with be appreciated.

~a::

KeyWait, a
KeyWait, a, D T.3

If (ErrorLevel)
{
Send {a down}
While GetKeyState("a", "p")
Send {a up}
}
Return

If (!ErrorLevel)
{
Send {1 down}
While GetKeyState("a", "p")
Send {1 up}
}
Return


## keyboard – 2020 MacBook not waking with LG Ultrawide monitor and MX keys and mouse

I have an issue which I been researching with no luck. I have an ultrawide LG monitor set up to 3 laptops with the MX keys and mouse 3. (1)2020 MacBook Pro via Apple usc-c adapter with HDMI cable to the screen, the other laptops one via HDMI the other via display port. When switching between screens via monitor, all work perfect with the exception of my MacBook. The MacBook will not wake by moving the mouse, touching the key board etc. I physically have to open the lid for the MacBook to wake. Once that is done all accessories work fine, the moment I switch to another source the issue returns. I have I have tried several recommendations found on Apple forums and online with no luck. Anyone else have experience similar issues with MacBook waking with external monitor and keyboard & mouse? Appreciate your feedback.

## Databases and B-Trees: What are Keys and how are they related

I confused about the description & definition of “key” occuring as terminology for databases and b-trees.

In first case dealing with theory of databases a key is defined as a choice for minimal subset $$K subset A := {A_1,A_2,…,A_n}$$ of a fixed set of attributes $$A_i$$ parametizing a data table (consisting of relations; a single relation is abstraction of a row in the table), where each attribute is literally a column specifying a property of objects = relations.

A key is characterized by property that there exist no two different relations (a relation is a row) which have exactly the same values for all attributes which belong to the key. And a key is a minimal subset with this property, ie there not exist a proper smaller subset of attributes contained in the key and having the property described in last sentence. Clearly keys are not unique. So the set of a keys is certain subset of the power set of the set attributes $$A_i$$. See also here: https://en.wikipedia.org/wiki/Unique_key

On the other hand the key concept occures as well for b-trees: https://en.wikipedia.org/wiki/B-tree#Definition

Here keys are a priori numbers or integers and different knots of b-tree contain different totally ordered subsets of keys where the total order on the space of keys is inherited from the order “$$ge$$” for integers $$mathbb{Z}$$. Especially the set of keys is a totally ordered subset of integers.

Question: How are the two concept of ‘key’ related to each other? My first idea was that if we consider in light of for definition (as elements of power set of attributes), we can simply randomly enumerate all the keys (that is associate to each key an number; formally speaking to specify an injection $$f:mathcal{K} to mathbb{Z}, K mapsto f(K)$$ where $$mathcal{K} subset Omega(A)$$)

and then treat them as numbers when working with b-trees. Is this exactly the correct connection or is there another deeper one and my approach is wrong?

## shortcut keys – Correct way to copy-paste file location from nautilus into a file chooser?

To paste a file or directory into the file-chooser dialogue of any application, I used to be able to select and copy the file from any Nautilus window with Ctrlc, then paste the whole pathname into the file-name field of the chooser with Ctrlv, whatever directory it was currently showing.

Since Ubuntu 19.04 (Nautilus 3.30), when you copy a file in Nautilus the clipboard includes a two-line media-type and action before the path, as follows:

x-special/nautilus-clipboard
copy
file:///path/name


So, when you paste into the file-name field of a chooser dialogue, it no longer works – you get just the first line x-special/nautilus-clipboard not the pathname.

Is there a correct way to paste these new 3-line Nautilus path-names into the file-name field of a file-chooser?

I’ve discovered a work-round where I can type Ctrll in Nautilus and copy the path of the containing directory, then type Ctrll in the file-chooser and paste the containing directory with Ctrlv. This at least gets the chooser to the right location in the file system, but you still have to select the file you want. So this feels more like a walk-round the houses than a work-round!

From reading the developer’s discussions, inclusion of this metadata in the clipboard seems to be part of some master-plan. For instance, once I had copied one of these 3-line Nautilus path names to my clipboard, I noticed that right clicking on a gnome-terminal shows a new entry Paste as filenames, which pastes the filename(s) surrounded by quotes {see Note 1}.

So, is the master-plan that a matching paste action will eventually be written for the file-chooser that recognizes this new 3-line clipboard entry? But in the meantime we’re left with a temporary regression? Or perhaps there is some new way that I’m meant to be pasting these pathnames – hence my question.

{Note 1}: Incidentally, Paste is also on the right-click menu of gnome-terminal, which allows you to paste the above three lines into the terminal. Useful eh? I imagine no-one will use that menu more than once! Similarly, Ctrl-Shift-v used to paste the pathname, but now it pastes the above three lines into the terminal.

## security – Does mnemonic phrase contain everything in my wallet including future keys?

I am confused about something important …

Most wallets allow wallet recovery using “Mnemonic phrase”, but (in general) with this phrase, do I get access to all my data ? E.g future generated addresses that will hold my bitcoins ?

Another way to ask: is this the only thing I need to store or do I also need to export my actual wallet/keys when I generate a new address or receive new coins ?

I know each wallet works differently but I think this would be a general question.
If it matters, I noticed the Mnemonic feature on Electrum and Coinomi wallets.

Edit: how can Coinomi give me access to different coins using same mnemonic phrase ? Does this mean that it is more like a password to my data (data stored by them) and if their wallet service becomes unavailable I don’t really have access to any of my different coins ?

## Collect matching elements of a python List from Dictionary keys – Python

Hi, I am trying to write a script/function for this problem but I am no where close. Any help regarding with the script is very much appreciated. I am new to python, and I am using python 2.7. (Script in pandas also works)

I have two csv files. File1 - Contains two columns, 'Name' and 'Category'.

Name,Category
Apple, Fruit
Apple,breakfast
Apple,Juice
Pineapple, Fruit
Pineapple,breakfast
Pineapple,Juice
spinach,juice
spinach,lunch
spinach,dressing

File2 - Contains a single column 'Name'

Name
banana 3 oz
Apple 2 oz
Pineapple 4
spinach 40 oz
Apple Lot


step 1 – I need read these two files – which I am able to do.
Assuming I should read the first file and store the values in a dictionary and second file values in a python list

file_1: {‘Apple’:(‘Fruit’,’breakfast’,’juice’), ‘Pineapple’: (‘Fruit’,’breakfast’,’juice’), ‘spinach’:(‘juice’,’lunch’,’dressing)

file_2 : (banana 3 oz,Apple 2 oz,Pineapple 4,spinach 40 oz,Apple Lot,Pineapple Salad)

step 2 – I need to collect the matching elements of the list from a dictionary keys (i.e., Apple, Pineapple,Spinach)
step 3 – then create a dictionary with the matching list elements and the matching dictionary values
(i.e., Apple 2 oz,Pineapple 4,spinach 40 oz,Apple Lot,Pineapple Salad)

Finaloutput: {'Apple 2 oz': ('Fruit','breakfast','juice'), 'Apple Lot':('Fruit','breakfast','juice'), 'Pineapple 4':('Fruit','breakfast','juice'), 'Pineapple Salad' :('Fruit','breakfast','juice'), 'spinach 40 oz' : ('juice','lunch','dressing)}

I need to write the final output into a csv file in this following format.

Name,Category
Apple 2 oz,Fruit
Apple 2 oz,breakfast
Apple 2 oz,Juice
Pineapple 4,Fruit
Pineapple 4,breakfast
Pineapple 4,Juice
spinach 40 oz,juice
spinach 40 oz,lunch
spinach 40 oz,dressing
Apple Lot,Fruit
Apple Lot,breakfast
Apple Lot,Juice

Thanks a lot once again.


## Relation between bitcoin address/private keys size and number of characters?

There are many types of Bitcoin addresses. Your example specifies (legacy) pay-to-pubkey-hash (P2PKH) address defined by Base58 check encoding and Wallet Import Format (WIF) which is also specified by base58 check

Base58 encoding treats the entire input payload as a big-endian big integer. Consider these alternate examples:

Input value: bc in ASCII: 0x62 0x63 (2 bytes) interpreted as a 2-byte int and encoded without leading zeros…

base 2: 110001001100011 (15 characters)

base 10: 25187 (5 characters)

base 16: 6263 (4 characters)

base 58: 8VG (3 characters)

So going forwards we know that for this example it took 3 base58 characters to encode two bytes. Lets run it backwards and try minimum and maximum values:

base 58, maximum value with 3 characters zzz encodes three byte value: 0x02fa27

base 58, minimum value with 3 characters 211 encodes two byte value: 0x0d24

Conclusion:

From this example alone we discover that we can not determine the length in bytes of the original value based just on the length in characters of the encoded string.

### Bonus:

Modern addresses are now encoded with bech32 and represent Segregated Witness programs. The bech32 spec is defined in BIP173 and look like this: bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4

bech32 encoding does not use interpretation as big integers and instead maps input bytes more directly to output characters:

The data-part values:

• 1 byte: the witness version
• A conversion of the 2-to-40-byte witness program (as defined by BIP141) to base32:
• Start with the bits of the witness program, most significant bit per byte first.
• Re-arrange those bits into groups of 5, and pad with zeroes at the end if needed.
• Translate those bits to characters using the table above.

As a result of the previous rules, addresses are always between 14 and
74 characters long, and their length modulo 8 cannot be 0, 3, or 5.
Version 0 witness addresses are always 42 or 62 characters, but
implementations MUST allow the use of any version.

So in summary, with a bech32 address you can determine the length in bytes of the input value based on the length in characters of the encoded string:

In bech32, each character represents 5 bits