Re: How to store variable data in a field?

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How to store variable data in a field?
Date: 2012-02-21 15:48:31
Message-ID: ji0ea0$s7u$1@dough.gmane.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Andre Lopes, 21.02.2012 16:11:
> Hi all,
>
> I need to create a table to store Twitter accounts information,
> Facebook and other social networks details for API login. I need to
> know if it is possible to store the account details("account_details"
> field) in a field that contains something like an array. I need to
> store this data in an array like field because the details for each
> social network accounts are different. What is my best choice for the
> field "account_details"?
>
> CREATE TABLE "account" (
> "id_account" int4 NOT NULL,
> "id_account_type" int4 NOT NULL,
> "n_account" varchar(50) NOT NULL,
> "account_details" varchar NOT NULL,
> "comment" varchar(2000),
> PRIMARY KEY("id_account","id_account_type")
> );
>
> I will need to store something like this:
>
> Twitter: array("account_name" => "xpto", "hash1" => "3432454355",
> "megahash" => "dfcf786fds987fds897")
> Facebook: array("account_name" => "xpto", "fb_special_hash" =>
> "dsdsad4535", "fb_security_hash" => "dsadsad454355",
> "fb_extended_hash" => "sdasfe5r4536556fsgg")
>
> It is possible to put something like that in a field? If yes, what
> datatype should I choose? Pros and cons of doing this?

Use the hstore datatype. That's exactly what you are looking for

http://stream.boxwatch.ru/docs/current/static/hstore.html

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Herman 2012-02-21 17:04:22 Combining data from Temp Tables
Previous Message Tom Lane 2012-02-21 15:29:32 Re: CROSS JOIN performance